package com.sunny;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test {

    public static void main(String[] args) throws ClassNotFoundException,
            IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException {
        MyClassLoader classLoader = new MyClassLoader();
        Class<?> clazz = classLoader.loadClass("TestDemo.class");
        Field[] fields = clazz.getDeclaredFields();
        Method[] method = clazz.getDeclaredMethods();
        System.out.println(fields.length + " " + method.length);
        System.out.println(method[0].getName());
        Object ins = clazz.newInstance();
        Object res = method[0].invoke(ins, 1, 2);
        System.out.println(res);
        res = clazz.getDeclaredMethod("add", new Class[] {int.class, int.class}).invoke(ins, 2, 6);
        System.out.println(res);
    }

}
